import { server } from '../server.js';
import { storeFile } from './Component/StoreFile.js';
import {respondReqDataMalformation} from './Component/Respond.js'

export const fileUpload = async (req, res, next) => {

    const data = req.body;
    console.log(data)
    var uri = data.uri;
    var base64 = data.base64;

    if (!(uri && base64)) {
        respondReqDataMalformation(res);
        return;
    }


    storeFile(base64, uri, './public/temp/', (filebase) => {

        if (filebase == '存储失败!') {
            res.status(200);
            res.json({ status: false, errinfo: '文件存储失败！' });
            return;
        }
    
        res.status(200);
        res.json({ status: true, filepath: server + '/temp/' + filebase });

    });

}